const { ElectronEgg } = require('ee-core');
const { Lifecycle } = require('./preload/lifecycle');
const { preload } = require('./preload');
const path = require('path');
const { spawn } = require('child_process');

// 启动 Webman 服务
const phpPath = path.join(__dirname, '../../build/extraResources/php8.0/php.exe');
const webmanPath = path.join(__dirname, '../../build/extraResources/webman/windows.php');
const phpProcess = spawn(phpPath, [webmanPath]);

phpProcess.stdout.on('data', (data) => {
    console.log(`[Webman] ${data}`);
  });



// new app
const app = new ElectronEgg();

// register lifecycle
const life = new Lifecycle();
app.register("ready", life.ready);
app.register("electron-app-ready", life.electronAppReady);
app.register("window-ready", life.windowReady);
app.register("before-close", life.beforeClose);

// register preload
app.register("preload", preload);



app.register('"before-close',()=>{
    phpProcess.kill();
    app.quit();
})


// 退出时终止 PHP 进程

// app.beforeClose = () => {
//     phpProcess.kill();
//     app.quit();
// }

// run
app.run();

